package com.dubito.noteapp.di

import android.app.Application
import androidx.room.Room
import com.dubito.noteapp.data.database.NoteDatabase
import com.dubito.noteapp.data.database.repository.NoteRepository
import com.dubito.noteapp.data.database.repository.NoteRepositoryImpl
import com.dubito.noteapp.domain.usecase.AddNote
import com.dubito.noteapp.domain.usecase.DeleteNote
import com.dubito.noteapp.domain.usecase.GetNote
import com.dubito.noteapp.domain.usecase.GetNotes
import com.dubito.noteapp.domain.usecase.NoteUseCases
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * author: LiLiang
 * createTime: 2022/10/7-11:23
 * remark:
 **/

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

    @Provides
    @Singleton
    fun provideNoteDatabase(context: Application): NoteDatabase {
        return Room.databaseBuilder(
            context, NoteDatabase::class.java,
            NoteDatabase.DATABASE_NAME
        ).build()
    }

    @Provides
    @Singleton
    fun provideNoteRepository(db: NoteDatabase): NoteRepository {
        return NoteRepositoryImpl(db.noteDao)
    }

    @Provides
    @Singleton
    fun provideNoteUseCases(repository: NoteRepository): NoteUseCases {
        return NoteUseCases(
            addNote = AddNote(repository),
            getNote = GetNote(repository),
            deleteNote = DeleteNote(repository),
            getNotes = GetNotes(repository)
        )
    }

}